package algotithm.acwing.test58;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @author zhouyanxiang
 * @Date 2020-12-2020/12/25-13:58
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {3, 32, 321};
        String s = solution.printMinNumber(nums);
        System.out.println(s);
    }


    public String printMinNumber(int[] nums) {
        StringBuilder str = new StringBuilder();
        int n = nums.length;
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nums[i]);
        }

        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                String s1 = o1 + "" + o2;
                String s2 = o2 + "" + o1;
                return s1.compareTo(s2);
            }
        });

        for (Integer res : list) {
            str.append(res);
        }
        return str.toString();
    }
}
